package com.sgx.learning.luban.homework.attributes.ext.stackmapframe;

import com.sgx.learning.luban.homework.attributes.ext.stackmapframe.checkvariable.VerificationTypeInfo;
import com.sgx.learning.luban.homework.basictype.U2;
import com.sgx.learning.luban.homework.constantpool.ConstantPoolInfo;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

@Data
public class FullFrame extends StackMapFrame{

    private short offsetDelta;
    private short numberOfLocals;
    private VerificationTypeInfo[] locals;
    private short numberOfStack;
    private VerificationTypeInfo[] stacks;
    @Override
    public void read(InputStream is, ConstantPoolInfo[] constantPoolInfos) throws IOException {
        this.offsetDelta = U2.read(is).getValue();
        this.numberOfLocals = U2.read(is).getValue();
        if(numberOfLocals > 0) {
            locals = new VerificationTypeInfo[numberOfLocals];
            for (int i = 0; i < numberOfLocals; i++) {
                VerificationTypeInfo temp = getTagFromInputStream(is);
                locals[i] = temp;
            }
        }
        numberOfStack = U2.read(is).getValue();
        if(numberOfStack > 0) {
            stacks = new VerificationTypeInfo[numberOfStack];
            for (int i = 0; i < numberOfStack; i++) {
                VerificationTypeInfo temp = getTagFromInputStream(is);
                stacks[i] = temp;
            }
        }
    }
}
